package com.shitou.shitoumember.controller;

import java.util.Arrays;
import java.util.Map;

import com.shitou.shitoucommons.annotation.CheckUserLogin;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.shitou.shitoumember.entity.SendReceiveEntity;
import com.shitou.shitoumember.service.SendReceiveService;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.RespBean;



/**
 * 保存用户与之交流的人数
 *
 * @author shitouren
 * @email 3076767823@qq.com
 * @date 2023-04-14 02:46:20
 */
@RestController
@RequestMapping("shitoumember/sendreceive")
public class SendReceiveController {
    @Autowired
    private SendReceiveService sendReceiveService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = sendReceiveService.queryPage(params);

        return RespBean.success().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public RespBean info(@PathVariable("id") Long id){
        SendReceiveEntity sendReceive = sendReceiveService.getById(id);

        return RespBean.success().put("sendReceive", sendReceive);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody SendReceiveEntity sendReceive){
        sendReceiveService.save(sendReceive);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody SendReceiveEntity sendReceive){
        sendReceiveService.updateById(sendReceive);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] ids){
        sendReceiveService.removeByIds(Arrays.asList(ids));

        return RespBean.success();
    }


    /**
     * 登陆会员创建双方聊天的中间表信息，用以链接
     * @param memberId
     * @param beingMemberId
     * @return
     */
    @ApiOperation(value = "登陆会员创建双方聊天的中间表信息，用以链接")
    @CheckUserLogin
    @PostMapping("/createSendReceive")
    public RespBean createSendReceive(@RequestParam Long memberId, @RequestParam Long beingMemberId){
        return sendReceiveService.createSendReceive(memberId, beingMemberId);
    }


    /**
     * 删除当前登录用户所聊天的对象，伪删除
     * @param memberId
     * @param beingMemberId
     * @return
     */
    @ApiOperation(value = "删除当前登录用户所聊天的对象，伪删除")
    @CheckUserLogin
    @PostMapping("/deleteSendReceive")
    public RespBean deleteSendReceive(@RequestParam Long memberId, @RequestParam Long beingMemberId){
        return sendReceiveService.deleteSendReceive(memberId, beingMemberId);
    }


    /**
     * 获取当前登录用户聊天的所有用户的id
     * @param memberId
     * @return
     */
    @ApiOperation(value = "获取当前用户聊天的所有用户的id")
    @CheckUserLogin
    @PostMapping("/getMemberReceive")
    public RespBean getMemberReceive(@RequestParam Long memberId){
        return sendReceiveService.getMemberReceive(memberId);
    }






}
